package com.jianyun.jyzs.dao;

import android.content.Context;

import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.QueryBuilder;
import com.jianyun.jyzs.bean.AnnouncementComment;
import com.jianyun.jyzs.db.DatabaseHelper;


import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.jianyun.jyzs.utils.RceLog;

/**
 * Created by mlli on 2017/11/20.
 */

public class AnnCommentDao {
    private Context context;
    private Dao<AnnouncementComment.AnnComment,Integer> dao;
    private DatabaseHelper helper;

    public AnnCommentDao(Context context) {
        this.context = context;
        try {
            helper = DatabaseHelper.getHelper(context);
            dao = helper.getDao(AnnouncementComment.AnnComment.class);
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    public void insert(AnnouncementComment.AnnComment annComment, String enterpriseCode){
        try {
            annComment.setEnterpriseCode(enterpriseCode);
            RceLog.d("lml","插入"+annComment.getCommentContent());
            dao.createOrUpdate(annComment);
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }

    public List<AnnouncementComment.AnnComment> getAnnCommentList(String id, String enterpriseCode){
        RceLog.d("lml","newsid="+id+"enterpriseCode="+enterpriseCode);
        List<AnnouncementComment.AnnComment> query = new ArrayList<>();
        QueryBuilder<AnnouncementComment.AnnComment, Integer> builder = dao.queryBuilder().orderBy("dtLong",false);
        try {
            builder.where().eq("newsId",id) ;
            query = builder.query();
            return query;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return query;
    }
}
